package com.controller;

import com.pojo.User;
import com.service.AlipayService;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class AlipayController {

    @Resource
    private UserService userService;

    @Autowired
    private AlipayService alipayService;

    @PostMapping("/pay")
    @ResponseBody
    public String pay(@RequestParam String outTradeNo, @RequestParam double totalAmount, @RequestParam String subject, @RequestParam String body) {
        try {
            return alipayService.createPayment(outTradeNo, totalAmount, subject, body);
        } catch (Exception e) {
            e.printStackTrace();
            return "支付失败";
        }
    }

    @PostMapping("/notify")
    public String notify(@RequestBody String notifyData) {
        // 处理支付宝的异步通知
        // 验证签名，处理订单状态等
        return "success";
    }

    @RequestMapping("/index")
    public String index(){
        return "index";
    }
}